<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>用户管理</title>
<script src="../js/jquery1.9.1.js" type="text/javascript"></script>
<script src="../js/jquery.pager.js" type="text/javascript"></script>
<script src="../js/iframeAuto.js" type="text/javascript"></script>
<script src="../js/overlay.js" type="text/javascript"></script>
<link href="../js/Pager.css" rel="stylesheet" type="text/css" />
<link href="../styles/edas_back.css" rel="stylesheet" type="text/css" />
</head>
<body>
	<div id="mainContainer" style="Margin-Right: auto; Margin-Left: auto;"
		align="left">
		<a id="test_id" href="#">test</a>

		<table id="data_table_id" class="admin">
			<tr id="start_id">
			
			</tr>
		</table>

		<br> <br> <br>
		<div id="pager"></div>
		
		<table id="table_model_id"  style="display: none">
			<tr id="tr_model_1">
				<td rowspan="2" width="100px" id="user_image_id">
					<img id="user_pic_id" src="../images/youc-11.png" width="57px" height="57px">
				</td>
				<td width="120px" id="user_name_id">姓名：张三</td>
				<td width="200px" id="user_depart_id">部门：三部</td>
				<td width="200px" id="user_position_id">职务：局长</td>
				<td rowspan="2" width="100px" height="55px">
					<a id="edit_id" href="#" title="编辑"><img border="0px" src="../images/btn_edit.png"/></a>
					<a id="del_id" href="#" title="删除"><img  border="0px" src="../images/btn_delete.png"/></a>
				</td>
			</tr>
			<tr id="tr_model_2">
				<td id="user_sex_id" class="jiazhong">性别：男</td>
				<td id="user_number_id" class="jiazhong">工号：12234234</td>
				<td id="user_mobile_id" class="jiazhong">手机号码：24324234243</td>
			</tr>
		</table>

	</div>
	<script>
		$(function(){
			init(1);
			$('#test_id').click(function() {
				  $(this).overlay({
				   closeOnClick: true
				  });
				});
		});
		//默认加载  
		function init(pagenumber) {
			jQuery.ajax({
				type : 'Get',
				contentType : 'application/json',
				url : '../user/userList.do',
				data : {
					currPage : pagenumber
				},
				dataType : 'json',
				success : function(data) {
					if (data.result) {
						$("#pager").pager({
							pagenumber : pagenumber,
							pagecount : data.obj.totalPage,
							buttonClickCallback : PageClick
						});
						
						//删除表格原先数据
						$('#data_table_id tr').each(
							function(){
								if($(this).attr("id") != "start_id"){
									$(this).remove();		
								}
							}
						);
						
						try{
							//为表格设置数据
							var userList = data.obj.userList;
							for(var i in userList){
								//alert(userList[i].user.userName);
								var user = userList[i].user;
								var userVcard = userList[i].userVcard;
								var htm1 = $('#tr_model_1').html();
				          		var newTr1 = "<tr>"+htm1+"</tr>";
				          		var newTr1Obj = $('#start_id').after(newTr1).next();
				          		
				          		var htm2 = $('#tr_model_2').html();
				          		var newTr2 = "<tr>"+htm2+"</tr>";
				          		var newTr2Obj = newTr1Obj.after(newTr2).next();
				          		newTr1Obj.find("#user_name_id").html("姓名："+userVcard.name);
				          		newTr1Obj.find("#user_depart_id").html("部门："+userVcard.dep);
				          		newTr1Obj.find("#user_position_id").html("职务："+userVcard.position);
				          		if(userVcard.avatar)
				          			newTr1Obj.find("#user_pic_id").attr("src",userVcard.avatar);
				          		newTr1Obj.find("#edit_id").attr("href","./editUser.html?userId="+user.userId);
				          		newTr1Obj.find("#del_id").click(
				          			function(){
										if(!confirm("确定要彻底删除该用户！")){
											return;				          				
										}
				          				jQuery.ajax({
				        					type : 'Get',
				        					contentType : 'application/json',
				        					url : '../user/del.do',
				        					data : {
				        						id : user.userId 
				        					},
				        					dataType : 'json',
				        					success : function(obj) {
				        						if (obj.result) {
				        							alert('删除数据成功');
				        							init(1);
				        						} else {
				        							alert('数据库异常,删除数据失败');
				        						}
				        					},
				        					error : function(data) {
				        						alert("error")
				        					}
				        				});		
				          			}
				          		);
				          		var sex;
				          		if(userVcard.sex == 0){
				          			sex = "男";
				          		}else{
				          			sex = "女";
				          		}
				          		
				          		newTr2Obj.find("#user_sex_id").html("性别："+sex);
				          		newTr2Obj.find("#user_number_id").html("工号："+userVcard.number);
				          		newTr2Obj.find("#user_mobile_id").html("手机号码："+user.userName);
							}
						}catch(e){
							
						}
						//调整iframe高度
						autoIframe();
					} else {

					}
				},
				error : function(data) {
					alert("error");
				}
			});
		}

		//回调函数  
		PageClick = function(pageclickednumber) {
			init(pageclickednumber);
		}
	</script>
</body>
</html>